/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  dev
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

//                  x2     x3
//                  |      |
//                    inlet
//                  6______9 ------ y3
//                  |      |
//                  |  b1  | valveStem
//          ------> |      |
//          |       7_____10 ------ y2
//          |      /
//  cylinderHead  /  valveHead
//        2 ____ 3 ___________12 -- y0
//        |      |             |
// liner  |  b0  |     b2      | symmetry
//        |      |             |
//        4 ____ 5 ___________13 -- y1
//
//          ------ piston ------
//
//        |      |             |
//        x0     x1            x4

valveLift 0; // Fixed for closed valve
pistonPos -4;

cylinderWidth 26;
meshSecWidth  2;
valveStem     2;
valveHead     1;
spacing       1;
inletHeight   8;

// Vertical mesh density
nPiston 8;
nValve 8; // Required, since foamDictionary does a general value substitution
nInlet 24;

// Horizontal mesh density
nx0 4;
nx1 #calc "ceil(2.0*$nx0)";
nx2 #calc "ceil(3.75*$nx0)";

x0 #calc "(3.0*$meshSecWidth - $cylinderWidth) / 4.0";
x1 #calc "$x0 + $spacing";
x2 #calc "$x1 + $valveHead";
x3 #calc "-$valveStem / 2.0";
x4 0.0;

y0 $valveLift;
y1 $pistonPos;
y2 $valveHead;
y3 $inletHeight;
y4 #calc "$valveLift + $valveHead"; // unused

z0 0.0;
z1 0.5;

vertices
(
    ($x0 0.0 $z0) //0
    ($x1 0.0 $z0) //1
    ($x0 $y0 $z0) //2
    ($x1 $y0 $z0) //3
    ($x0 $y1 $z0) //4
    ($x1 $y1 $z0) //5
    ($x2 $y3 $z0) //6
    ($x2 $y2 $z0) //7
    ($x2 $y4 $z0) //8
    ($x3 $y3 $z0) //9
    ($x3 $y2 $z0) //10
    ($x3 $y4 $z0) //11
    ($x4 $y0 $z0) //12
    ($x4 $y1 $z0) //13

    ($x0 0.0 $z1) //14
    ($x1 0.0 $z1) //15
    ($x0 $y0 $z1) //16
    ($x1 $y0 $z1) //17
    ($x0 $y1 $z1) //18
    ($x1 $y1 $z1) //19
    ($x2 $y3 $z1) //20
    ($x2 $y2 $z1) //21
    ($x2 $y4 $z1) //22
    ($x3 $y3 $z1) //23
    ($x3 $y2 $z1) //24
    ($x3 $y4 $z1) //25
    ($x4 $y0 $z1) //26
    ($x4 $y1 $z1) //27
);

blocks
(
    hex (2 4 5 3 16 18 19 17) ($nPiston $nx0 1) simpleGrading (1 1 1)
    hex (6 7 10 9 20 21 24 23) ($nInlet $nx1 1) simpleGrading (1 1 1)
    hex (3 5 13 12 17 19 27 26) ($nPiston $nx2 1) simpleGrading (1 1 1)
);

defaultPatch
{
    name    frontAndBack;
    type    empty;
}

boundary
(
    piston
    {
        type    wall;
        faces
        (
            (4 5 18 19)
            (5 13 19 27)
        );
    }

    liner
    {
        type    wall;
        faces
        (
            (4 2 18 16)
        );
    }

    cylinderHead
    {
        type    wall;
        faces
        (
            (2 3 17 16)
            (7 6 20 21)
        );
    }

    inlet
    {
        type    patch;
        faces
        (
            (6 9 23 20)
        );
    }

    valveHead
    {
        type    wall;
        faces
        (
            (7 21 24 10)
            (12 3 17 26)
        );
    }

    valveStem
    {
        type    wall;
        faces
        (
            (9 10 24 23)
        );
    }

    symmetry
    {
        type    patch;
        faces
        (
            (12 13 27 26)
        );
    }
);

// ************************************************************************* //
